package com.db.patterns.singleton.demo04;

import java.io.Serializable;

/**
 * 懒汉式 - 双重检查锁
 */
public class Singleton implements Serializable {
    private Singleton() {
    }

    private static volatile Singleton instance;
    private static final Object lock = new Object();

    public static Singleton getInstance() {
        if (instance == null) {
            synchronized (lock) {
                if (instance == null) {
                    instance = new Singleton();
                }
            }
        }
        return instance;
    }
}
